const path = require("path")

const Version = new Date().getTime()
const { js_ver } = {
  js_ver: `2020${Version}`,
  css_ver: `2020${Version}`,
  img_ver: `2020${Version}`,
}

const isPro = process.env.NODE_ENV === "development"

module.exports = {
  // 部署应用包时的基本 URL,用法和 webpack 本身的 output.publicPath 一致
  publicPath: "./",
  // 输出文件目录
  outputDir: "dist",
  // eslint-loader 是否在保存的时候检查
  lintOnSave: true,

  configureWebpack: {
    output: {
      // 输出重构  打包编译后的 文件名称  【模块名称.版本号.时间戳】
      filename: `./script/[name].${js_ver}.js`,
      chunkFilename: `./script/[name].${js_ver}.js`,
    },

    resolve: {
      alias: {
        "@": path.resolve(__dirname, "./src"),
        "~": path.resolve(__dirname, "./public"),
      },
    },
  },
  chainWebpack: (config) => {
    config.module
      .rule("images")
      .exclude.add(path.resolve(__dirname, "./public/assets"))
      .end()
      .use("url-loader")
      .tap(() => ({
        limit: 1024 * 10, // 稍微改大了点
        fallback: {
          loader: require.resolve("file-loader"),
          options: {
            name: "static/img/[name].[hash:8].[ext]",
            esModule: false,
          },
        },
      }))
      .end()
      .enforce("post")
  },
  productionSourceMap: isPro,
}
